package com.insurance.aop;

import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Arrays;


/**
 * Created with IntelliJ IDEA.
 * User: 朱雄
 * Date: 2020/10/16 18:23
 * Description:此类为切面类
 * Version: V1.0
 */

@Aspect
@Component
public class PrintAop {
    private  static Logger logger=Logger.getLogger(PrintAop.class);

    /**
     *
     * @param joinPoint
     */
    @Before("execution(* com.insurance.service.*.*(..) ) ")
    public static void beforeQuery(JoinPoint joinPoint){
        String classType = joinPoint.getTarget().getClass().getName();
        Object[] args=joinPoint.getArgs();
        logger.info(classType+"类中-"+joinPoint.getSignature().getName()+"方法调用前"+"传入参数"+Arrays.toString(args));
    }

    @After("execution(* com.insurance.service.*.*(..) ) ")
    public static void afterQuery(JoinPoint joinPoint){
        logger.info(joinPoint.getSignature().getName()+"方法调用后");

    }
//
//    @Around("execution(* com.gxa.service.*.*(..))")
//    public void aroundQuery(JoinPoint joinPoint){
//        System.out.println(joinPoint.getSignature().getName());
//        System.out.println("环绕增强");
//    }

    /**
     *
     * @param joinPoint
     * @param obj
     */
    @AfterReturning(value = "execution(* com.insurance.service.*.*(..))",returning = "obj")
    public void afterResQuery(JoinPoint joinPoint,Object obj){
            System.out.println(joinPoint.getSignature().getName());
            System.out.println("查询结果");
    }

    /**
     *
     * @param joinPoint
     * @param error
     */
    @AfterThrowing(value = "execution(* com.insurance.service.*.*(..))",throwing = "error")
    public void QueryThrow(JoinPoint joinPoint,Throwable error){
       logger.error(joinPoint.getSignature().getName()+":"+error.getMessage());
    }

}
